package com.kurumi.medical.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.kurumi.medical.datasource.TargetDataSource;
import com.kurumi.medical.mapper.HospNoteBasicJsonMapper;
import com.kurumi.medical.util.StringUtil;
import com.kurumi.medical.service.HospNoteBasicJsonService;

@Service
public class HospNoteBasicJsonServiceImpl implements HospNoteBasicJsonService {

	@Autowired
	private HospNoteBasicJsonMapper hospNoteBasicJsonMapper;
	
	
	@TargetDataSource(name="ds1")
	@Transactional(propagation=Propagation.REQUIRED)
	@Override
	public int addHospNoteBasicJson(String hospNoteBasicJson) {
	
		return hospNoteBasicJsonMapper.insert(hospNoteBasicJson);
	}


	@TargetDataSource(name="ds1")
	@Transactional(readOnly=true)
	@Override
	public String getHospBasicJsonByFirstGuid(String firstGuid) {
		String hospNoteJson=null;
		List<String> hospNoteJsonList=hospNoteBasicJsonMapper.getHospBasicJsonByFirstGuid(firstGuid);
		if(hospNoteJsonList!=null && hospNoteJsonList.size()>0){
			hospNoteJson=hospNoteJsonList.get(0);
		}
		return hospNoteJson;
	}


	@TargetDataSource(name="ds1")
	@Transactional(propagation=Propagation.REQUIRED)
	@Override
	public int updateHospBasicJsonByFirstGuid(String firstGuid,String hosBasicJson) {
		//删除json数据
		hospNoteBasicJsonMapper.deleteHospBasicJsonByFirstGuid(StringUtil.handleJsonParam(firstGuid));
		hospNoteBasicJsonMapper.insert(hosBasicJson);
		return 0;
	}
}
